import apiClient from "../apiClient";
import { PORT1 } from "./config/servicePort";
import type { UserInfoResponse, UserToken, NavMenu } from "#/entity";

export interface SignInReq {
	username: string;
	password: string;
	captcha?: string; // 验证码
	uuid?: string; // 验证码id
}

export interface SignUpReq extends SignInReq {
	email: string;
}
// 登录返回类型
export type SignInRes = UserToken;
// 用户api
export const userApi = {
	signIn: `${PORT1}/sys/login`,
	signUp: `${PORT1}/auth/signup`,
	logout: `${PORT1}/auth/logout`,
	refresh: `${PORT1}/auth/refresh`,
	user: `${PORT1}/sys/user/info`,
	menu: `${PORT1}/sys/menu/nav`,
} as const;
// 登录
const signin = (data: SignInReq) => apiClient.post<SignInRes>({ url: userApi.signIn, data });
// 注册
const signup = (data: SignUpReq) => apiClient.post<SignInRes>({ url: userApi.signUp, data });
// 退出
const logout = () => apiClient.get({ url: userApi.logout });
// 获取用户信息
const findById = () => apiClient.get<UserInfoResponse>({ url: userApi.user });
// 获取菜单
const findMenu = () => apiClient.get<NavMenu>({ url: userApi.menu });
// 用户api
export default {
	signin,
	signup,
	findById,
	logout,
	findMenu,
};
